# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=kustomize
pkgver=4.5.5
pkgrel=0
pkgdesc="Template-free customization of Kubernetes YAML manifests"
url="https://kustomize.io/"
license="Apache-2.0"
arch="all"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/kubernetes-sigs/kustomize/archive/kustomize/v$pkgver/kustomize-$pkgver.tar.gz"
builddir="$srcdir/kustomize-kustomize-v$pkgver/kustomize"

export GOFLAGS="$GOFLAGS -trimpath -mod=readonly -modcacherw"
export GOPATH="$srcdir"
export CGO_ENABLED=0

build() {
	local builddate="$(date -u "+%Y-%m-%dT%TZ" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})"

	go build -ldflags="-s -w
		-X sigs.k8s.io/kustomize/api/provenance.version=$pkgver
		-X sigs.k8s.io/kustomize/api/provenance.buildDate=$builddate
		"

	./kustomize completion bash > $pkgname.bash
	./kustomize completion fish > $pkgname.fish
	./kustomize completion zsh > $pkgname.zsh
}

check() {
	go test ./...
}

package() {
	install -Dm755 kustomize -t "$pkgdir"/usr/bin

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/completions/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
db2375977059eeb0479adf842c5ddd42db15216a872bab66e7a2cbd595e4d5d8ba32d66f50ad1ebc5a5b3db8b16c60ecf9ae44bd58f63dff1c03c6fb450554f0  kustomize-4.5.5.tar.gz
"
